<template>
  <div class="app-container">
    <el-card class="mar_bottom">
      <el-search-form label-width="90px" @search="onSearch" @reset="onReset">
        <el-form-item>
          <el-select
            size="small"
            style="width: 100px; margin-right: -2px"
            v-model="timeType"
            placeholder="请选择"
          >
            <el-option label="操作时间" value="createDate"></el-option>
          </el-select>
          <el-date-picker
            size="small"
            v-model="searchBody.timeRange"
            style="width: 350px"
            type="datetimerange"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="yyyy-MM-dd HH:mm:ss"
            :default-time="['00:00:00', '23:59:59']"
          ></el-date-picker>
        </el-form-item>
        <el-form-item label="装修公司">
          <el-select size="small" v-model="searchBody.companyId" filterable placeholder="请选择">
            <el-option
              v-for="item in companyList"
              :key="item.id"
              :label="item.companyName"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="城市">
          <el-cascader
            v-model="regionNameList"
            size="small"
            :options="regionTree"
            :props="{
              label: 'name',
              value: 'name',
              checkStrictly: true,
            }"
            clearable
          ></el-cascader>
        </el-form-item>
      </el-search-form>
    </el-card>

    <el-card>
      <el-tabs
        style="margin-top: 15px"
        v-model="searchBody.sysType"
        @tab-click="getData"
      >
        <el-tab-pane label="全部" name="0"></el-tab-pane>
        <el-tab-pane label="后台系统" name="1">
          <el-tabs v-model="searchBody.moduleName" @tab-click="getData">
            <el-tab-pane label="全部" name="0"></el-tab-pane>
            <el-tab-pane label="后台用户模块" name="后台用户模块"></el-tab-pane>
            <el-tab-pane label="后台订单模块" name="后台订单模块"></el-tab-pane>
            <el-tab-pane label="后台装修公司模块" name="后台装修公司模块"></el-tab-pane>
          </el-tabs>
        </el-tab-pane>
        <el-tab-pane label="美宅商家" name="2">
          <el-tabs v-model="searchBody.moduleName" @tab-click="getData">
            <el-tab-pane label="全部" name="0"></el-tab-pane>
            <el-tab-pane label="装修公司账号模块" name="装修公司账号模块"></el-tab-pane>
            <el-tab-pane label="装修公司订单模块" name="装修公司订单模块"></el-tab-pane>
            <el-tab-pane label="装修公司记录模块" name="装修公司记录模块"></el-tab-pane>
          </el-tabs>
        </el-tab-pane>
        <el-tab-pane label="美宅聚宝" name="3"></el-tab-pane>
      </el-tabs>


      <el-pagination
        small
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageNo"
        :page-sizes="pageSizeOpts"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalCount"
      >
      </el-pagination>
      <div class="have-pagination-container">
        <el-table v-loading="loading.list" :data="list" border   show-overflow-tooltip="true">
          <el-table-column type="expand">
            <template slot-scope="scope">
              <el-form label-position="left" inline class="demo-table-expand">
                <el-form-item label="ID">
                  <span>{{ scope.row.id }}</span>
                </el-form-item>
                <el-form-item label="操作人">
                  <span>{{ scope.row.createUserValue }}</span>
                </el-form-item>
                <el-form-item label="请求参数">
                  <span>{{ scope.row.request }}</span>
                </el-form-item>
                <el-form-item label="响应参数">
                  <span>{{ scope.row.response }}</span>
                </el-form-item>
                <el-form-item label="归属地查询结果">
                  <span>{{ scope.row.aiwenResponse }}</span>
                </el-form-item>

              </el-form>
            </template>
          </el-table-column>
          <el-table-column
            label="ID"
            prop="id"
            align="center"
            width="80"
          ></el-table-column>
          <el-table-column
            label="操作时间"
            prop="createDate"
            align="center"
            width="150"
          ></el-table-column>
          <el-table-column
            label="操作人"
            prop="createUserValue"
            align="center"
            width="100"
          ></el-table-column>
          <el-table-column
            label="系统类型"
            prop="sysTypeValue"
            align="center"
            width="100"
          ></el-table-column>
          <el-table-column
            label="模块"
            prop="moduleName"
            align="center"
            width="100"
          ></el-table-column>
          <el-table-column
            label="模块描述"
            prop="moduleValue"
            align="center"
            width="200">
          </el-table-column>
          <el-table-column
            label="方法路径"
            prop="methodPath"
            align="center"
            width="200">
          </el-table-column>
          <el-table-column
            label="请求IP"
            prop="requestIp"
            align="center"
            width="150"
          ></el-table-column>
          <el-table-column
            label="请求地址"
            prop="requestAddress"
            align="center"
            width="200"
          ></el-table-column>
          <el-table-column
            label="耗时(ms)"
            prop="time"
            align="center"
            width="100">
          </el-table-column>
          <el-table-column
            label="响应状态"
            prop="responseSuccessValue"
            align="center"
            width="100">
            <template slot-scope="scope">
              <el-tag
                :type="scope.row.responseSucess === 1 ? '' : 'danger'"
                disable-transitions>{{scope.row.responseSuccessValue}}</el-tag>
            </template>
          </el-table-column>


        </el-table>
      </div>
      <el-pagination
        small
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageNo"
        :page-sizes="pageSizeOpts"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalCount"
      >
      </el-pagination>
    </el-card>







  </div>
</template>

<script>
import {
  paidanOrder,
  selectPaidanPageVo,
  exportInData,
  exportOutData,
  jiazhuangdingdanshenhe,
  updateUserLevel, selectShouyiPgeByOrder, selectShouYiPageByUser,
  userSetYaoqingma,
  qrCode, selectZxRegionTree, selectTopUpLogVoPageData, setTopUpPrice, selectCompanyVoList,
  selectAdminLogIpRegionTree, selectRegionTree

} from "@/api/api.js";
import {sysDict_delete} from "@/api/dataDict";
import {selectAdminLogPage} from "@/api/platformSys";

const getDefaultForm = () => ({
  id:null,
  levelId:null,
  userId:null,
  yaoqingma:null,
  topUpPrice:0,
  remark:null,
});
const getDefaultSearchBody = () => ({
  timeRange: null,
  resource: null,
  phone: null,
  yezhu: null,
  orderNo: null,
  userIdList: null,
  id: null,
  audiStatus: "0",
  levelId:null,
  yaoqingma:null,
  topUpStatus:null,
  companyId:null,
  sysType:null,
  oldSysType:0,
  moduleName:null,
});
export default {
  data() {
    return {
      regionTree: [],
      companyList:[],
      regionNameList:null,
      topUpShuidanDialogImage:null,
      topUpShuidanDialogImageList:[],
      orderRiZhi: [],
      areaOptions: [],
      qdzOptions: [],
      resourceOptions: [],
      fw1Options: [],
      fw2Options: [],
      zxfs1Options: [],
      zxfs2Options: [],
      zxfs3Options: [],
      zxfs4Options: [],
      xhfgOptions: [],
      zxysOptions: [],
      jsStatusOptions: [],
      timeType: "createDate",
      searchType: "phone",
      dialogTitle: "",
      dialogTitle2: "",
      dialogTitle3: "",
      handleType: "",
      shenhetongguoTitle:"审核通过",
      pageNo: 1,
      pageSize: 20,
      totalCount: 0,
      childPageNo: 1,
      childPageSize: 20,
      childTotalCount: 0,
      shenhetongguoDialog:false,
      shenheshibaiDialog:false,
      pageSizeOpts: [20, 50, 100, 300, 500],
      loading: {
        list: false,
        list2: false,
        childList: false,
      },
      zxRegionList: [],
      list: [],
      paidanData: {},
      selectRow: [], // 选中
      lookDialog: false,
      editDialog: false,
      paidanDialog: false,
      zxRegionDialog: false,
      updateForm: getDefaultForm(),
      searchBody: getDefaultSearchBody(),
      configDialog:false,
      yaoqingmaDialog:false,
      tableColumn: [
        {
          label: "线索ID",
          checked: true,
        },
        {
          label: "线索业主",
          checked: true,
        },
        {
          label: "线索手机",
          checked: true,
        },
        {
          label: "线索城市",
          checked: true,
        },
        {
          label: "派单",
          checked: true,
        },
        {
          label: "接单",
          checked: true,
        },
        {
          label: "订单",
          checked: true,
        },
        {
          label: "结算",
          checked: true,
        },
        {
          label: "标记",
          checked: true,
        },
        {
          label: "更新小计",
          checked: true,
        },
        {
          label: "来源",
          checked: true,
        }
       /* {
          label: "管理员/渠道主/达人",
          checked: true,
        },*/
        /*{
          label: "手机归属",
          checked: true,
        },
        {
          label: "线索时间",
          checked: true,
        },
        {
          label: "需求时间（订单）",
          checked: true,
        },
        {
          label: "更新时间",
          checked: true,
        },
        {
          label: "更新人",
          checked: true,
        },*/
      ],
      tableColumn2: [
        {
          label: "线索ID",
          checked: true,
        },
        {
          label: "订单GUID",
          checked: false,
        },
        {
          label: "线索UUID",
          checked: true,
        },
        {
          label: "线索姓名",
          checked: true,
        },
        {
          label: "线索城市",
          checked: true,
        },
        {
          label: "线索时间",
          checked: true,
        },
        {
          label: "渠道主",
          checked: true,
        },
        {
          label: "达人",
          checked: true,
        },
        {
          label: "派单时间",
          checked: true,
        },
        {
          label: "接单时间",
          checked: true,
        },
        {
          label: "产生需求",
          checked: true,
        },
        {
          label: "需求时间(订单)",
          checked: true,
        },
        {
          label: "需求城市",
          checked: true,
        },
        {
          label: "渠道主奖励",
          checked: true,
        },
        {
          label: "达人奖励",
          checked: true,
        },
        {
          label: "结算状态",
          checked: true,
        },
        {
          label: "结算时间",
          checked: true,
        },
      ],
      shouyiUserId: 0,
      shouyiDialog: false,
    };
  },
  created() {
    this.getData();
    this.getRegionData();
    //this.getQdzOptions();
    //this.getOptions();
  },
  methods: {
    handleRowClick(row) {
      this.$refs.Table.toggleRowExpansion(row);
    },

    onSearchTypeChange(key) {
      let val;
      for (let key2 of ["yezhu", "phone", "orderNo", "id"]) {
        val = this.searchBody[key2] || val;
      }
      this.searchBody = Object.assign(this.searchBody, {
        [key]: val,
      });
    },
    getData() {
      var sysType = this.searchBody.sysType;
      if(this.searchBody.moduleName === '0'){
        this.searchBody.moduleName = null;
      }
      if(sysType != this.searchBody.oldSysType){
          // 变了
        this.searchBody.moduleName = null;
      }
      this.searchBody.oldSysType = this.searchBody.sysType;
      this.loading.list = true;
      const { timeRange, userIdList, ...rest } = this.searchBody;
      const [startTime, endTime] = timeRange || [null, null];
      /*const _userIdList = (userIdList || []).reduce((a, b) => {
        return Array.from(new Set(a.concat(b)));
      }, []);*/
      selectAdminLogPage({
        pageNo: this.pageNo,
        pageSize: this.pageSize,
        startTime: startTime,
        endTime: endTime,

        ...rest,
      }).then(({ result }) => {
        this.list = result.data;
        this.totalCount = result.totalCount;
        this.loading.list = false;
      });


    },
    getRegionData(){
      selectAdminLogIpRegionTree().then(({ result }) => {
        this.regionTree = result || [];
      });
    },
    handleCurrentChangeChild(type, val) {
      switch (type) {
        case "list":
          this.pageNo = val;
          this.getData();
          break;
        case "childList":
          this.childPageNo = val;
          this.getShouyiData();
          break;
      }
    },
    handleSizeChangeChild(type, val) {
      switch (type) {
        case "list":
          this.pageSize = val;
          this.getData();
          break;
        case "childList":
          this.childPageSize = val;
          this.getShouyiData();
          break;
      }
    },
    getData2() {},
    handleSizeChange(val) {
      this.pageSize = val;
      this.getData();
    },
    shouyiTableRowClassName({row, rowIndex}){
      if (row.levelValue === '黄金') {
        return 'huangjing-row';
      }
      return '';

    },
    handleCurrentChange(val) {
      this.pageNo = val;
      this.getData();
    },
    handleSelectionChange(val) {
      this.selectIds = val.map((d) => d.id);
    },
    onSearch() {
      this.pageNo = 1;
      this.getData();
    },
    onReset() {
      this.pageNo = 1;
      this.searchBody = getDefaultSearchBody();
      this.getData();
    },
    getZxTreeData(id) {
      selectZxRegionTree({
        id:id
      }).then(({ result }) => {
        this.zxRegionList = result || [];
      });
    },
    getShouyiData() {
      this.loading.childList = true;
      selectShouYiPageByUser({
        pageNo: this.childPageNo,
        pageSize: this.childPageSize,
        userId: this.shouyiUserId,
      })
        .then(({ result = {} }) => {
          this.childList = result.data;
          this.childTotalCount = result.totalCount;
          this.loading.childList = false;
        })
        .catch(() => {
          this.loading.childList = false;
        });
    },
    handleClick(type, row, title) {
      this.handleType = type;
      switch (type) {
        case "shenheshibai":
          this.updateForm.id=row.id;
          this.shenheshibaiDialog = true;
          this.shenhetongguoTitle = "审核失败 ："+row.companyName;
          this.topUpShuidanDialogImage = row.topUpShuidanIamge;
          this.topUpShuidanDialogImageList = [];
          this.topUpShuidanDialogImageList.push(row.topUpShuidanIamge);
          break;
        case "shenhetongguo":
          this.updateForm.id=row.id;
          this.shenhetongguoDialog = true;
          this.shenhetongguoTitle = "审核通过 ："+row.companyName;
          this.topUpShuidanDialogImage = row.topUpShuidanIamge;
          this.topUpShuidanDialogImageList = [];
          this.topUpShuidanDialogImageList.push(row.topUpShuidanIamge);
          break;
        case "zxRegion":

          this.zxRegionDialog = true;
          this.shouyiUserId = row.id;
          this.getZxTreeData(row.id);
          break;
        case "selectTuanduiVo":
          break;
        case "updateQrcode":
          this.$confirm(`确认生成新二维码？`, "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          }).then(() => {
            qrCode({
              id: row.id,
            }).then((res) => {
              this.$message.success(res.msg || "操作成功");
              this.getData();
            });
          });
          break;
        case "setYaoqingma":
          this.dialogTitle = "用户:" + row.phone;
          this.yaoqingmaDialog = true;
          this.updateForm.userId = row.id;
          break;
        case "setLevel":
          this.dialogTitle = "订单ID:" + row.id + "-" + title;
          this.configDialog = true;
          this.updateForm.userId = row.id;
          break;
        case "updateSetLevel":
          console.log("123");
          break;
        case "add":
          this.dialogTitle2 = "营销-添加";
          this.editDialog = true;
          this.updateForm = getDefaultForm();
          break;
        case "update":
          this.dialogTitle2 = "营销ID:" + row.id + "-编辑";
          selectXiansuoInfoVo({
            id: row.id,
          }).then((res) => {
            const { provinceCode, cityCode, areaCode, ...rest } = res.result;
            this.updateForm = Object.assign(rest, {
              addrCode: [provinceCode, cityCode, areaCode],
            });
            this.editDialog = true;
          });
          break;
        case "fenpai":
          break;
        case "exportOut":
          exportOutData().then((res) => {
            this.$message.success("导出成功");
          });
          break;
        case "paidan":
          this.dialogTitle3 = "订单ID:" + row.id + "-派单";
          selectPaidanPageVo({
            id: row.id,
          }).then((res) => {
            const paidanData = res.result || {};
            paidanData.orderId = row.id;
            this.paidanData = paidanData;
            this.paidanDialog = true;
          });
          break;
        case "shenhe":
          this.$confirm(`确认审核通过？`, "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          }).then(() => {
            jiazhuangdingdanshenhe({
              id: row.id,
            }).then((res) => {
              this.$message.success(res.msg || "操作成功");
              this.getData();
            });
          });
          break;
        case "selectShouyi":
          this.shouyiDialog = true;
          this.shouyiUserId = row.id;
          this.getShouyiData();
          break;
        default:
          return;
      }
    },
    handleSure(type) {
      console.log(type);
      type = type || this.handleType;
      //const { addrCode, ...rest } = this.updateForm;
      switch (type) {
        case "setShenhetongguo":
          var topUpPriceValue = this.updateForm.topUpPrice;
          var topUpPrice = topUpPriceValue.trim();
          if (topUpPrice === '') {
            alert('请输入金额');
            return false;
          }
          if (!/^\d+(\.\d{1,2})?$/.test(topUpPrice)) {
            alert('金额需为有效数字，例如：100.00');
            return false;
          }
          this.$confirm(`确认审核通过？`, "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          }).then(() => {
            setTopUpPrice(
              {
                id:this.updateForm.id,
                topUpPrice:this.updateForm.topUpPrice,
                remark:this.updateForm.remark,
                topUpStatus:"5"
              }
            ).then((res) => {
              this.$message.success(res.msg || "操作成功");
              this.getData();
            });
          });
          break;
        case "setShenheshibai":
          this.$confirm(`确认审核失败？`, "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          }).then(() => {
            setTopUpPrice(
              {
                id:this.updateForm.id,
                remark:this.updateForm.remark,
                topUpStatus:"2"
              }
            ).then((res) => {
              this.$message.success(res.msg || "操作成功");
              this.getData();
            });
          });
          break;
        case "updateSetLevel":
          this.$confirm(`确认修改等级？`, "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          }).then(() => {
            updateUserLevel(
              {
                id:this.updateForm.userId,
                levelId:this.updateForm.levelId
              }
            ).then((res) => {
              this.$message.success(res.msg || "操作成功");
              this.getData();
            });
          });
          break;
        case "updateSetYqm":
          this.$confirm(`确认修改邀请码？`, "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          }).then(() => {
            userSetYaoqingma(
              {
                id:this.updateForm.userId,
                yaoqingma:this.updateForm.yaoqingma
              }
            ).then((res) => {
              this.$message.success(res.msg || "操作成功");
              this.getData();
            });
          });
          break;
        case "paidan":
          paidanOrder({
            orderId: this.paidanData.orderId,
            jiazhuangPlatformIdList: this.selectRow.map((d) => {
              return d.jiazhuangPlatformId;
            }),
          }).then((res) => {
            this.$message.success("派单成功");
            this.paidanDialog = false;
          });
          break;
        default:
          return;
      }
    },
    onSelectionChange(val) {
      this.selectRow = val;
    },
    handleCommand(command) {
      this.$message("click on item " + command);
    },
    uploadData(params) {
      const form = new FormData();
      form.append("file", params.file);
      const loading = this.$loading({
        lock: true,
        text: "正在导入...",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)",
      });
      exportInData(form)
        .then((res) => {
          this.$message.success("导入成功");
          loading.close();
        })
        .catch(() => {
          loading.close();
        });
    },
    beforeUpload(file) {
      if (file.size > 1 * 1024 * 1024) {
        this.$message.warning("上传的文件大小不能超过1MB!");
        return false;
      }
    },
  },
};
</script>

<style>
.power_right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 30px;
  margin-bottom: 10px;
}

.block {
  display: flex;
  height: 70px;
}
.block_item {
  padding: 5px 30px;
  box-sizing: border-box;
  border-right: 1px solid #ddd;
  color: #5f5f5f;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
}
.block_item:first-of-type {
  border-right: 0;
  align-self: flex-start;
}
.value {
  font-size: 24px;
  font-weight: bold;
}
.baijin-row {
  background: #fffbec;
}

.huangjing-row {
  background: #fff740;
}
.zuanshi-row {
  background: #95ffff;
}

.table-cell-ellipsis .cell {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
</style>
